﻿@{
    ViewData["Title"] = "StorySelect";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<StorySeries> storySeries = ViewBag.storySeriesList;
    List<StoryCard> storyCards = ViewBag.storyCards;
}
<link rel="stylesheet" href="~/css/defaultStyle.css" type="text/css" />

<h2>故事列表<button class="btn btn-primary" style="float:right" onclick="newstory()">浏览新故事</button></h2>

<hr />
<!--用户先进入故事选择--继续故事或重新开始-》index，或选择新的故事-》NewStory-->

<div id="content" class="container"> 
    <h1>进行中</h1>
    @if (storySeries.Count == 0)
    {
        <div class="row">
            <h1>未有进行中的故事</h1>
            <p><a onclick="newstory()">寻找新故事</a></p>
        </div>
    }
    
    @foreach (var i in storySeries)
    {
        if (i.Status == NewCity.Enum.enumStoryStatus.进行中)
        {
            <div class="col-md-6 unitcell">
                <h2>@i.SeriesName</h2>
                <p>@(storyCards.Where(a => a.StorySeriesID == i.ID).FirstOrDefault() == null ? "新故事" : storyCards.Where(a => a.StorySeriesID == i.ID).FirstOrDefault().StoryName)</p>
                <button class="btn btn-primary" onclick="storycontinue('@i.ID')">继续</button>
                <button class="btn btn-primary" onclick="restart('@i.ID')">重新开始</button>
            </div>
        }
    }
</div>
<div class="container">
    <hr>
    <h1>已完成</h1>
    @foreach (var i in storySeries)
    {
        if (i.Status == NewCity.Enum.enumStoryStatus.结束)
        {
            <div class="col-md-6 unitcell">
                <h2>@i.SeriesName</h2>
                <p>@(storyCards.Where(a => a.StorySeriesID == i.ID).FirstOrDefault() == null ? "新故事" : storyCards.Where(a => a.StorySeriesID == i.ID).FirstOrDefault().StoryName)</p>
                <button class="btn btn-primary" onclick="storycontinue('@i.ID')">继续</button>
                <button class="btn btn-primary" onclick="restart('@i.ID')">重新开始</button>
            </div>
        }
    }
</div>



<script>
    function storycontinue(seriesID) {
        debugger;
        window.location.href = '/Main/Main?SeriesID=' + seriesID
    }

    function newstory() {
        window.location.href = '/Main/NewStory/'
    }

    function restart(seriesID) {
        $.post('/Main/Restart', { StorySeriesID: seriesID }, function (data) {
            debugger;
            if (data == true) {
                window.location.href = '/Main/Main?SeriesID=' + seriesID
            }
            else {
                alert("发生错误！");
            }
        });

    }

</script>

